<template>
	<view class="content">
		<!-- <mescroll-uni @down="downCallback" @up="upCallback"  @init="mescrollInit"> -->
			
		<view class="mokuai" style="margin: 30rpx 40rpx;" @tap="goinfo" v-for="(item,index) in list" :key="index" :data-id="item.id">
			<view  style="padding: 20rpx;">
				<view class="clear shenhe-text" >
					<text class="left" style="color: #323232;font-size: 34rpx;">{{item.nickname}} </text>
					<text class="left phone-text" style="color: #323232;margin-left: 30rpx;">{{item.phone}}</text>
					<view class="right"  style="margin-right: -8px;"><switch :checked="item.is_lock==-1"   color='#ff5a5a !important' @tap.stop="change(item.id,index)" style="transform:scale(0.7)"/></view>
					<text class="right" v-if="item.is_lock==1">冻结</text>
					<text class="right" v-if="item.is_lock==-1" style="color: #ff5a5a;" >冻结</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">总额度（元） </text>
					<text class="right blue_text">{{item.capital}}</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">应还总额（元） </text>
					<text class="right blue_text">{{item.used_capital}}</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">贷款项数（个） </text>
					<text class="right ">{{item.loan_count}}</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">是否逾期 </text>
					<text class="right" v-if="item.is_over==1">否</text>
					<text class="right" v-if="item.is_over==-1" style="color: #ff5a5a;">是</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">销售经理 </text>
					<text class="right">{{item.manage_name}}</text>
				</view>
			</view>	
		</view>
		<image src="../../static/img/nodata.png" class="no-data" v-if="ishas1"  mode="widthFix"></image>
		<!-- <view class="mokuai" style="margin: 20rpx;" @tap="goinfo()">
			<view  style="padding: 20rpx;">
				<view class="clear shenhe-text" >
					<text class="left" style="color: #323232;">刘月月 </text>
					<text class="left phone-text" style="color: #323232;margin-left: 30rpx;">18193186350</text>
					<view class="right"><switch checked @change="switch1Change"style="transform:scale(0.7)"/></view>
					<text class="right">冻结</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">应还总额（元） </text>
					<text class="right blue_text">20000</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">贷款项数（个） </text>
					<text class="right ">5</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">是否逾期 </text>
					<text class="right">否</text>
				</view>
				<view class="clear shenhe-text" >
					<text class="left">销售经理 </text>
					<text class="right">否</text>
				</view>
			</view>	
		</view> -->
		<view style="height: 55px;"></view>
		<view class="footer">
			<button class="big_button button_shadow"  @tap="goaddkehu()">
				添加客户
			</button>
		</view>
		
		<!-- </mescroll-uni> -->
		
	</view>
</template>

<script>
	import httpPath from '@/static/js/path.js';
	import {getlogin} from '@/static/js/login.js';
	import {fmoney} from '@/static/js/login.js';
	import MescrollUni from "@/components/mescroll-uni/uni-load-more.vue";
	var  _self,
	page = 1;
	export default {
		data() {
			return {
				type: 0,
				list:[],
				dataList: [],
				name: '',
				user:{},
				ishas1:false,
				loadingType: 0,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			};
		},
		components: {
			MescrollUni
		},
		// components: {uniLoadMore},
		onLoad(e) {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}	
			page = 1;
			_self = this;
			// _self.type = e.id;
			_self.fnGetData();
		},
		onPullDownRefresh() {
			page=1
			_self.loadingType=0;
		    this.fnGetData();   
		    setTimeout(function () {
		            uni.stopPullDownRefresh();
		        }, 1000);
		},
		onShow() {
			this.user = getlogin();
			if(!this.user.islogin){
				uni.showModal({
				   showCancel:false,
				   content:"您还没有登录，请登录"
				})
				uni.navigateTo({
					url:"../public/login"
				})
			}	
			page = 1;
			_self.fnGetData();
		},
		onReachBottom: function() {
			if (_self.loadingType != 0) {//loadingType!=0;直接返回
				return false;
			}
			_self.loadingType = 1;
			uni.showNavigationBarLoading();//显示加载动画
			page++;//每触底一次 page +1
			uni.request({
				url: httpPath.filePath+"api.php/index/user/customer_list",
				method:'POST',
				header:{'content-type':'application/x-www-form-urlencoded'},
				data: {page:page,member_id:this.user.member_id,user_id:this.user.user_id},
				success: (res) => {
					if (res.data.result.length==0) {//没有数据
						_self.loadingType = 2;
						uni.hideNavigationBarLoading();//关闭加载动画
						return false;
					}
					for (let i = 0;i < res.data.result.length;i++) {
						res.data.result[i].capital=fmoney(res.data.result[i].capital)
						res.data.result[i].use_capital=fmoney(res.data.result[i].use_capital)
						res.data.result[i].used_capital=fmoney(res.data.result[i].used_capital)
						_self.list.push(res.data.result[i]);
						// this.list[i].capital=fmoney(this.list[i].capital)
						// this.list[i].use_capital=fmoney(this.list[i].use_capital)
				 	    //this.list[i].used_capital=fmoney(this.list[i].used_capital)
					}
					_self.loadingType = 0;//将loadingType归0重置
					uni.hideNavigationBarLoading();//关闭加载动画
				}
			});
		
		},
		methods: {
		goaddkehu(id){
			uni.navigateTo({
				url:"editkehu"
			})
		},
		goinfo(e){
			uni.navigateTo({
				url:"kehuinfo?id="+e.currentTarget.dataset.id
			})
		},
	    //冻结客户
		change(id,index){				
			if(this.list[index].is_lock==1){
					this.list[index].is_lock=-1
				}else{
					this.list[index].is_lock=1
				}
				uni.request({
					url: httpPath.filePath+"/api.php/index/user/customer_lock/",
					method:'POST',
					header:{'content-type':'application/x-www-form-urlencoded'},
					data: {member_id:this.user.member_id,is_lock:this.list[index].is_lock,id:id,user_id:this.user.user_id},
					success: (res) => {
						
					}
				});
			},
			// goaddkehu(id){
			// 	uni.navigateTo({
			// 		url:"editkehu"
			// 	})
			// },
			fnGetData(){
				uni.request({
					url: httpPath.filePath+"api.php/index/user/customer_list",
					method: 'POST',
					data:  {page:page,member_id:this.user.member_id,user_id:this.user.user_id},
					header:{'content-type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == "200"){
							this.list = res.data.result;
							if(this.list.length==0){
								this.ishas1=true;
							}else{
								this.ishas1=false;
							}
							for(let i=0;i<this.list.length;i++){
								this.list[i].capital=fmoney(this.list[i].capital)
							}
						}
					}
				});
			},
			
		},
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				if(this.userInfo.jibie == 4){
					uni.navigateTo({
						url: 'add'
					})	
				}
			}
		}
	}
</script>

<style>
	@import "../../colorui/main.css";
	.phone-text{background: url(../../static/img/phone-icon.png)no-repeat;background-position: 2px 5px;background-size: 10px;}
    .footer{height: 55px;position: fixed;bottom: 0px;left: 0px;width: 100%;box-shadow: -1px -1px 1px #dce0e7;display: flex;flex-direction: row;padding: 5px 0px;background: #FFFFFF;}
</style>
